package com.website.web.front.controller;

import com.website.common.annotation.Log;
import com.website.common.core.controller.BaseController;
import com.website.common.core.domain.AjaxResult;
import com.website.common.core.page.TableDataInfo;
import com.website.common.enums.BusinessType;
import com.website.common.utils.poi.ExcelUtil;
import com.website.custom.domain.WOnline;
import com.website.custom.service.IWOnlineService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.view.RedirectView;

import java.util.List;

/**
 * 在线预约Controller
 * 
 * @author ruoyi
 * @date 2024-12-03
 */
@Controller
@RequestMapping("/online")
public class OnlineController extends BaseController
{
    private String prefix = "custom/online";

    @Autowired
    private IWOnlineService wOnlineService;

    @GetMapping()
    public String online()
    {
        return prefix + "/online";
    }

    /**
     * 查询在线预约列表
     */
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(WOnline wOnline)
    {
        startPage();
        List<WOnline> list = wOnlineService.selectWOnlineList(wOnline);
        return getDataTable(list);
    }

    /**
     * 导出在线预约列表
     */
    @Log(title = "在线预约", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(WOnline wOnline)
    {
        List<WOnline> list = wOnlineService.selectWOnlineList(wOnline);
        ExcelUtil<WOnline> util = new ExcelUtil<WOnline>(WOnline.class);
        return util.exportExcel(list, "在线预约数据");
    }

    /**
     * 新增在线预约
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存在线预约
     */
    @Log(title = "在线预约", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public RedirectView addSave(WOnline wOnline)
    {
        wOnlineService.insertWOnline(wOnline);
        RedirectView redirectView = new RedirectView();
        redirectView.setUrl("/contact");
        return redirectView;
    }

    /**
     * 修改在线预约
     */
    @RequiresPermissions("system:online:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        WOnline wOnline = wOnlineService.selectWOnlineById(id);
        mmap.put("wOnline", wOnline);
        return prefix + "/edit";
    }

    /**
     * 修改保存在线预约
     */
    @RequiresPermissions("system:online:edit")
    @Log(title = "在线预约", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(WOnline wOnline)
    {
        return toAjax(wOnlineService.updateWOnline(wOnline));
    }

    /**
     * 删除在线预约
     */
    @RequiresPermissions("system:online:remove")
    @Log(title = "在线预约", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(wOnlineService.deleteWOnlineByIds(ids));
    }
}
